package com.admin.action.bookaction;


import com.admin.Action;
import com.admin.dto.BookListBean;
import com.admin.service.bookservice.BookServiceImpl;
import com.admin.service.bookservice.BookServiceInF;
import com.google.gson.Gson;


import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;

import java.util.List;


public class BookListAction extends Action {
    @Override
    public void execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        PrintWriter out=response.getWriter();
        HttpSession session = request.getSession();
//        System.out.println(session.getAttribute("adminInfo"));
        if(session.getAttribute("adminInfo")==null){
            out.println("<script>parent.window.location.href='error.html';</script>");
            return;
        }

        BookServiceInF service= new BookServiceImpl();
        int count= service.getCount();

        out.print(count);
//        System.out.println(count);
//
//        Map map=new HashMap();
//        map.put("count",count);
//        System.out.println(request.getParameter("index"));

        int index= Integer.parseInt(request.getParameter("index"));
//        System.out.println(index);
//        int pageSize= Integer.parseInt(request.getParameter("pageSize"));
        out.print(",");


        List<BookListBean>  booksBeans=service.bookList(index,4);
//        request.setAttribute();
        //发送数据条数
        Gson gson = new Gson();
        String jsonStr =   gson.toJson(booksBeans);
        out.print(jsonStr);
//        System.out.println(jsonStr);
//        out.print(service.getCount());


    }
}
